'use strict';

const low = require('lowdb');
const FileSync = require('lowdb/adapters/FileSync');
const Controller = require('egg').Controller;

class AR1Controller extends Controller {

  async index() {
    const { ctx } = this;

    const db = low(new FileSync('./data/index.json'));

    ctx.body = db.getState().ar1;
  }

  async update() {
    const { ctx } = this;

    const { ar1 } = this.ctx.request.body;
    const db = low(new FileSync('./data/update.json'));

    db.setState({ ar1 }).write();

    ctx.body = 'Updated';
  }
}

module.exports = AR1Controller;
